package com.herui.ota.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.herui.ota.entity.DeviceOta;
import com.herui.ota.entity.DeviceOtaSoft;
import com.herui.ota.entity.UserDept;
import com.herui.ota.enums.OpsTypeEnum;
import com.herui.ota.pojo.form.DeviceOtaSoftFilterForm;
import com.herui.ota.pojo.form.DeviceOtaSoftForm;
import com.herui.ota.pojo.form.NoneFilterForm;
import com.herui.ota.pojo.vo.DeviceOtaSoftVo;
import com.herui.ota.service.DeviceOtaSoftService;
import com.herui.ota.service.UserDeptService;
import com.mlnx.common.annotations.NeedLogin;
import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import com.mlnx.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.shan.spring.base.CurdBaseController;
import org.shan.spring.base.RdBaseController;
import org.shan.spring.base.annotations.SysLog;
import org.shan.spring.mybatis.service.ICurdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.Serializable;
import java.util.Collection;

/**
 * Created by amanda.shan on 2020/5/19.
 */
@SysLog(title = "otaSoft")
@Api(value = "otaSoft接口", tags = {"otaSoft接口"})
@RestController
@RequestMapping("/otaSoft")
public class DeviceOtaSoftController extends CurdBaseController<DeviceOtaSoft,DeviceOtaSoftForm, DeviceOtaSoftForm,
        DeviceOtaSoftFilterForm> {

    @Autowired
    private DeviceOtaSoftService service;

    @Override
    public ICurdService getService() {
        return service;
    }

    @Override
    public DeviceOtaSoft newInstance(Integer id) {
        DeviceOtaSoft userDept = new DeviceOtaSoft();
        userDept.setId(id);
        return userDept;
    }

    @NeedLogin
    @SysLog(
            businessType = BusinessType.INSERT
    )
    @ApiOperation(
            value = "新增",
            notes = ""
    )
    @PostMapping({""})
    public Response add(@Valid DeviceOtaSoftForm form) throws IllegalAccessException, InstantiationException {
        service.save(form);
        return this.result();
    }

    @NeedLogin
    @SysLog(
            businessType = BusinessType.UPDATE
    )
    @ApiOperation(
            value = "更改",
            notes = ""
    )
    @PutMapping({"/{id}"})
    public Response modify(@PathVariable("id") Integer id, @Valid DeviceOtaSoftForm form) {
        service.update(id, form);
        return this.result();
    }

    @NeedLogin
    @SysLog(
            businessType = BusinessType.UPDATE
    )
    @ApiOperation(
            value = "更改状态",
            notes = ""
    )
    @PutMapping({"/state/{id}"})
    public Response modifyState(@PathVariable("id") Integer id, String state) {
        service.update(id, state);
        return this.result();
    }

    @NeedLogin
    @ApiOperation(
            value = "获取固件",
            notes = ""
    )
    @GetMapping({"/soft"})
    public ResponseData<DeviceOtaSoftVo> getDeviceOtaSoft(String series, String channel) {
        return this.result( service.getDeviceOtaSoft(series, channel));
    }

}
